package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.SecurityUtils;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.AProject;
import com.isdepci.project.carbon.service.IAProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目列Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/carbon/project")
public class AProjectController extends BaseController
{
    @Autowired
    private IAProjectService aProjectService;



    /**
     * 查询个人项目列表
     */
    @GetMapping("/selectProjectByUser")
    public AjaxResult selectProjectByUser() {
        List<AProject> list =  aProjectService.selectProjectByUserId(SecurityUtils.getUserId());
        return AjaxResult.success(list);
    }


    /**
     * 查询项目列列表
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(AProject aProject)
    {
        startPage();
        List<AProject> list = aProjectService.selectAProjectList(aProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列列表
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:export')")
    @Log(title = "项目列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AProject aProject)
    {
        List<AProject> list = aProjectService.selectAProjectList(aProject);
        ExcelUtil<AProject> util = new ExcelUtil<AProject>(AProject.class);
        return util.exportExcel(list, "project");
    }

    /**
     * 获取项目列详细信息
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return AjaxResult.success(aProjectService.selectAProjectById(projectId));
    }

    /**
     * 新增项目列
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:add')")
    @Log(title = "项目列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AProject aProject)
    {
        return toAjax(aProjectService.insertAProject(aProject));
    }

    /**
     * 修改项目列
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:edit')")
    @Log(title = "项目列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AProject aProject)
    {
        return toAjax(aProjectService.updateAProject(aProject));
    }

    /**
     * 删除项目列
     */
//    @PreAuthorize("@ss.hasPermi('carbon:project:remove')")
    @Log(title = "项目列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(aProjectService.deleteAProjectByIds(projectIds));
    }
}
